Import csv into mysql using Python
import csvimport MySQLdbmydb = MySQLdb.connect(host='localhost', user='lineimp', passwd='', db='mydb')cursor = mydb.cursor()csv_data = csv.reader(file('lines.csv'))for row in csv_data: cursor.execute('INSERT INTO lines(USER_PRODUCT_ID, USER_NAME, PROD_NAME, AMOUNT )' 'VALUES("%s", "%s", "%s")', row)mydb.commit()cursor.close()print "Done"
You must be logged in to post. Please login or register an account.